{"ast":null,"code":"import classNames from 'classnames';\nimport * as React from 'react';\nfunction UnitNumber(_ref) {\n  let {\n    prefixCls,\n    value,\n    current,\n    offset = 0\n  } = _ref;\n  let style;\n  if (offset) {\n    style = {\n      position: 'absolute',\n      top: `${offset}00%`,\n      left: 0\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    style: style,\n    className: classNames(`${prefixCls}-only-unit`, {\n      current\n    })\n  }, value);\n}\nfunction getOffset(start, end, unit) {\n  let index = start;\n  let offset = 0;\n  while ((index + 10) % 10 !== end) {\n    index += unit;\n    offset += unit;\n  }\n  return offset;\n}\nexport default function SingleNumber(props) {\n  const {\n    prefixCls,\n    count: originCount,\n    value: originValue\n  } = props;\n  const value = Number(originValue);\n  const count = Math.abs(originCount);\n  const [prevValue, setPrevValue] = React.useState(value);\n  const [prevCount, setPrevCount] = React.useState(count);\n  // ============================= Events =============================\n  const onTransitionEnd = () => {\n    setPrevValue(value);\n    setPrevCount(count);\n  };\n  // Fallback if transition event not support\n  React.useEffect(() => {\n    const timeout = setTimeout(() => {\n      onTransitionEnd();\n    }, 1000);\n    return () => {\n      clearTimeout(timeout);\n    };\n  }, [value]);\n  // ============================= Render =============================\n  // Render unit list\n  let unitNodes;\n  let offsetStyle;\n  if (prevValue === value || Number.isNaN(value) || Number.isNaN(prevValue)) {\n    // Nothing to change\n    unitNodes = [/*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n      key: value,\n      current: true\n    }))];\n    offsetStyle = {\n      transition: 'none'\n    };\n  } else {\n    unitNodes = [];\n    // Fill basic number units\n    const end = value + 10;\n    const unitNumberList = [];\n    for (let index = value; index <= end; index += 1) {\n      unitNumberList.push(index);\n    }\n    // Fill with number unit nodes\n    const prevIndex = unitNumberList.findIndex(n => n % 10 === prevValue);\n    unitNodes = unitNumberList.map((n, index) => {\n      const singleUnit = n % 10;\n      return /*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n        key: n,\n        value: singleUnit,\n        offset: index - prevIndex,\n        current: index === prevIndex\n      }));\n    });\n    // Calculate container offset value\n    const unit = prevCount < count ? 1 : -1;\n    offsetStyle = {\n      transform: `translateY(${-getOffset(prevValue, value, unit)}00%)`\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    className: `${prefixCls}-only`,\n    style: offsetStyle,\n    onTransitionEnd: onTransitionEnd\n  }, unitNodes);\n}","map":{"version":3,"names":["classNames","React","UnitNumber","_ref","prefixCls","value","current","offset","style","position","top","left","createElement","className","getOffset","start","end","unit","index","SingleNumber","props","count","originCount","originValue","Number","Math","abs","prevValue","setPrevValue","useState","prevCount","setPrevCount","onTransitionEnd","useEffect","timeout","setTimeout","clearTimeout","unitNodes","offsetStyle","isNaN","Object","assign","key","transition","unitNumberList","push","prevIndex","findIndex","n","map","singleUnit","transform"],"sources":["/data/messenger.client/node_modules/antd/es/badge/SingleNumber.js"],"sourcesContent":["import classNames from 'classnames';\nimport * as React from 'react';\nfunction UnitNumber(_ref) {\n  let {\n    prefixCls,\n    value,\n    current,\n    offset = 0\n  } = _ref;\n  let style;\n  if (offset) {\n    style = {\n      position: 'absolute',\n      top: `${offset}00%`,\n      left: 0\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    style: style,\n    className: classNames(`${prefixCls}-only-unit`, {\n      current\n    })\n  }, value);\n}\nfunction getOffset(start, end, unit) {\n  let index = start;\n  let offset = 0;\n  while ((index + 10) % 10 !== end) {\n    index += unit;\n    offset += unit;\n  }\n  return offset;\n}\nexport default function SingleNumber(props) {\n  const {\n    prefixCls,\n    count: originCount,\n    value: originValue\n  } = props;\n  const value = Number(originValue);\n  const count = Math.abs(originCount);\n  const [prevValue, setPrevValue] = React.useState(value);\n  const [prevCount, setPrevCount] = React.useState(count);\n  // ============================= Events =============================\n  const onTransitionEnd = () => {\n    setPrevValue(value);\n    setPrevCount(count);\n  };\n  // Fallback if transition event not support\n  React.useEffect(() => {\n    const timeout = setTimeout(() => {\n      onTransitionEnd();\n    }, 1000);\n    return () => {\n      clearTimeout(timeout);\n    };\n  }, [value]);\n  // ============================= Render =============================\n  // Render unit list\n  let unitNodes;\n  let offsetStyle;\n  if (prevValue === value || Number.isNaN(value) || Number.isNaN(prevValue)) {\n    // Nothing to change\n    unitNodes = [/*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n      key: value,\n      current: true\n    }))];\n    offsetStyle = {\n      transition: 'none'\n    };\n  } else {\n    unitNodes = [];\n    // Fill basic number units\n    const end = value + 10;\n    const unitNumberList = [];\n    for (let index = value; index <= end; index += 1) {\n      unitNumberList.push(index);\n    }\n    // Fill with number unit nodes\n    const prevIndex = unitNumberList.findIndex(n => n % 10 === prevValue);\n    unitNodes = unitNumberList.map((n, index) => {\n      const singleUnit = n % 10;\n      return /*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n        key: n,\n        value: singleUnit,\n        offset: index - prevIndex,\n        current: index === prevIndex\n      }));\n    });\n    // Calculate container offset value\n    const unit = prevCount < count ? 1 : -1;\n    offsetStyle = {\n      transform: `translateY(${-getOffset(prevValue, value, unit)}00%)`\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    className: `${prefixCls}-only`,\n    style: offsetStyle,\n    onTransitionEnd: onTransitionEnd\n  }, unitNodes);\n}"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AACnC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,UAAU,CAACC,IAAI,EAAE;EACxB,IAAI;IACFC,SAAS;IACTC,KAAK;IACLC,OAAO;IACPC,MAAM,GAAG;EACX,CAAC,GAAGJ,IAAI;EACR,IAAIK,KAAK;EACT,IAAID,MAAM,EAAE;IACVC,KAAK,GAAG;MACNC,QAAQ,EAAE,UAAU;MACpBC,GAAG,EAAG,GAAEH,MAAO,KAAI;MACnBI,IAAI,EAAE;IACR,CAAC;EACH;EACA,OAAO,aAAaV,KAAK,CAACW,aAAa,CAAC,MAAM,EAAE;IAC9CJ,KAA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